export default function request(options) {
	let header = options.header || {};
	let data = options.data || {};
 
	let token = uni.getStorageSync('token');
	header['token'] = token ? token : "";
	
    //需要token的接口但是没有token
	if (!options.notNeedToken && !token) {
		uni.reLaunch({
			url: '/pages/login/login'
		});
		return new Promise((resolve, reject) => {
			reject({
				code:12,
				msg:'请登录'
			})
		})
	}
 
	//	发起请求 加载动画
	if (!options.hideLoading) {
		uni.showLoading({
			title: "加载中"
		})
	}
 
	//	发起网络请求
	return new Promise((resolve, reject) => {
		uni.request({
			url:options.url,
			method: options.method || 'GET',
			header: header,
			data: data,
			// dataType: "json",
			// sslVerify: false, //	是否验证ssl证书
			success: res => {
				if (res.statusCode && res.statusCode != 200) {
					return uni.showModal({
						content: res.errMsg ? res.errMsg : '出错了'
					})
				}
                //登录失效 token失效
				if(res.data.code === 100005002){
					uni.showToast({
						icon:'none',
						duration:3000,
						title:'登录失效，请重新登录'
					})
					return uni.reLaunch({
						url:'/pages/login/login'
					})
				}
				resolve(res.data)
			},
			fail: err => {
				uni.showModal({
					content: err.errMsg ? err.errMsg : "出错了"
				})
				reject(err)
			},
			complete: (e) => {
				uni.hideLoading()
				uni.stopPullDownRefresh();
			}
		})
	})
 
}